﻿using System;
using System.Threading;

namespace Skynet.CommonLibrary.ThreadRefreshTime.StrateGy
{
    /// <summary>
    /// 线程池
    /// </summary>
    ///<remarks>
    /// 作者：         李志强
    /// 开发时间：  2011-03-28
    /// </remarks>
    public class ThreadPoolStrategy:IThreadStrategy
    {
        private bool _isStop;
        #region IThreadSerategy 成员

        public void StartWork(Action workAction, int interval)
        {
            if (workAction == null)
                return;

            ThreadPool.QueueUserWorkItem(new WaitCallback(o => 
            {
                while (true)
                {
                    if (_isStop)
                        return;

                    workAction();
                    Thread.Sleep(interval);
                }
            }));
        }

        public void StopWork()
        {
            _isStop = true;
        }

        #endregion
    }
}
